

def f(nums,key):
    d = dict()
    l = len(nums)
    for i, e in enumerate(nums):
        if e == key and i < l - 1:
            if d.get(nums[i + 1]):
                d[nums[i + 1]] += 1
            else:
                d[nums[i + 1]] = 1
    print(d)

nums=[1,100,200,1,100];key=1
f(nums,key)